package com.avalon.shop.event;

import com.avalon.core.context.Context;
import com.avalon.shop.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ShopApplicationRunner implements ApplicationListener<ApplicationEvent> {
    private Context context;
    private ShopService shopService;

    public ShopApplicationRunner(Context context, ShopService shopService) {
        this.context = context;
        this.shopService = shopService;
    }


    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ApplicationReadyEvent) {
            try {
                shopService.backLogin();
            } catch (Exception e) {
                log.error("init login", e);
            }
        }
    }
}
